package edu.umassd.visual.components;

import java.awt.Color;
import java.text.DecimalFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import processing.core.PFont;
import edu.umassd.visual.Display;
import edu.umassd.visual.RADDACLDisplay;
import edu.umassd.visual.View;
import edu.umassd.visual.options.SelectFont;

/**
 * Shows the coordinates of the mouse.
 * 
 * @author Dan Avila
 */
@Component("coords")
public class Coordinates implements Displayable<RADDACLDisplay>
{
	private boolean visible = false;

	private static final DecimalFormat FORMAT = new DecimalFormat("0.00");

	@Autowired
	private SelectFont selectedFont;

	@Autowired
	private View view;

	@Override
	public void display(RADDACLDisplay display)
	{
		if (visible)
		{
			String dataX = FORMAT.format(view.canvasToDataX(display.mouseX));
			String dataY = FORMAT.format(view.canvasToDataY(display.mouseY));

			PFont font = selectedFont.getFont();

			display.fill(Color.WHITE);
			display.textFont(font);
			display.textAlign(Display.RIGHT);
			display.text(dataX + " : " + dataY, display.width - 10,
					display.height - 10);
		}
	}

	public void setVisible(boolean visible)
	{
		this.visible = visible;
	}
}
